# coding=utf-8

# import servers
import traceback

from tests.modules.ucloud.servers import servers
from tests.modules.ucloud.ucloud_db import UcloudZone, UcloudApp


def deal_all_db(_ip):
    ucZone = UcloudZone(ip=_ip)

    ucApp = UcloudApp(ip=_ip)

    ucZone.do_insert(zone_code='uc.euaws.warehouse.ukls',
                     zone_alias='ukls',
                     parent_code='uc.euaws.area',
                     title='英一存储仓',
                     order=20)

    ucZone.commit()

    ucApp.do_insert(app_name='cwm',
                    zone='uc.euaws.warehouse.ukls',
                    zone_alias='ukls',
                    port=36580,
                    app_type='tomcat',
                    db_name='cwm_ukls',
                    mem_level=1)
    ucApp.commit()

    ucApp.do_insert(app_name='dep',
                    zone='uc.euaws.warehouse.ukls',
                    zone_alias='ukls',
                    port=36380,
                    app_type='tomcat',
                    db_name='OWMS_UKLS',
                    mem_level=1)
    ucApp.commit()

    ucApp.do_insert(app_name='owms',
                    zone='uc.euaws.warehouse.ukls',
                    zone_alias='ukls',
                    port=36280,
                    app_type='adempiere',
                    db_name='OWMS_UKLS',
                    mem_level=1)
    ucApp.commit()

    ucApp.do_insert(app_name='SMQ',
                    zone='uc.euaws.warehouse.ukls',
                    zone_alias='ukls',
                    port=36480,
                    app_type='php',
                    db_name='',
                    mem_level=1)
    ucApp.commit()


for _ip in servers:
    try:
        print '准备刷新ucloud%s:' % _ip

        deal_all_db(_ip=_ip);
        print 'ucloud%s刷新完成:' % _ip

    except BaseException, ex:
        print traceback.format_exc()
